package com.hr.剑指offer.work1;

import java.util.Stack;

/**
 * @author 周恒哲
 * @date 2020/06/12
 **/
public class 面试题06_从尾到头打印链表 {
    //反转链表
    public static int[] reversePrint(ListNode head) {
        Stack<ListNode> stack=new Stack();
        ListNode temp=head;
        while (temp!=null){
            stack.add(temp);
            temp=temp.next;
        }
        int size = stack.size();
        int[] print=new int[size];
        for (int i = 0; i < size; i++) {
            print[i]=stack.pop().val;
        }
        return print;
    }

    public static void main(String[] args) {
        ListNode head=new ListNode(1);
        head.add(3);
        head.add(2);
        int[] ints = 面试题06_从尾到头打印链表.reversePrint(head);
        for (int i : ints) {
            System.out.println(i);
        }
    }
}
